#include <bits/stdc++.h>
using namespace std;
int bao[6001][81];
int n, m, k;
// 2个有序数组，a1,a2,...an，b1,b2,...bm，都是从小到大的顺序排列。
// 找出其中相同元素。
bool check(int *a, int *b) {

  int posA = 1;
  int posB = 1;
  int num = 0;
  while (posA <= m && posB <= m) {
    if (a[posA] == b[posB]) {
      num++;
      if (num > 1)
        return false;
      posA++, posB++;
    }

    else if (a[posA] > b[posB])
      posB++;
    else
      posA++;
  }
  return num == 1;
}

int main() {

  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> bao[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(bao[i] + 1, bao[i] + m + 1);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 2; j <= m; j++) {
      if (bao[i][j] == bao[i][j - 1]) {
        cout << "NO";
        return 0;
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (!check(bao[i], bao[j])) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";

  return 0;
}